package org.zxp.algorithm.hash;

import org.junit.Test;

import java.util.HashMap;

/**
 * @program: effectiveJava
 * @description:哈希算法测试
 * @author: X-Pacific zhang
 * @create: 2019-07-17 22:27
 **/
public class HashTest {
    public static void main(String[] args) {
        HashTest o1 = new HashTest();
        HashTest o2 = new HashTest();

        System.out.println(HashTest.hash(o1) & 15);
        System.out.println(HashTest.hash(o2) & 15);


        HashTest.decimalToBinary(15);
        HashTest.decimalToBinary(HashTest.hash(o1));
        HashTest.decimalToBinary(HashTest.hash(o2));

    }


    static final int hash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }

    static void decimalToBinary(int n) {
        StringBuilder binary = new StringBuilder();
        while (n != 0) {
            binary.insert(0, n % 2);
            n /= 2;
        }
        System.out.println("binary=" + binary.toString());
    }


    @Test
    public void testInitHashMap(){
        HashMap map = new HashMap(64);
        map.put(1, 1);
        map.put(2, 1);
    }

}
